﻿// ===============================================================================
// XCI.WinForm.Platform 西安交通信息WinForm开发框架 2019 版权所有
// ===============================================================================

using DevExpress.XtraSplashScreen;
using System.ComponentModel;
using System.Threading.Tasks;
using XCI.Core;
using XCI.Helper;
using XCI.Sys.Filter;
using XCI.Sys.Model;
using XCI.Sys.Service;

namespace XCI.Windows
{
    /// <summary>
    /// 用户下拉控件
    /// </summary>
    public class UserComboBoxEdit : ComboBoxEditx, IAsyncBindingData
    {
        public override string ValueMember => "Id";
        public override string DisplayMember => "Name";

        /// <summary>
        /// 是否显示全部项
        /// </summary>
        [DefaultValue(true)]
        [Category("XCI")]
        [Description("是否显示全部项")]
        public virtual bool AllItemVisible { get; set; } = true;

        /// <summary>
        /// 全部项文本
        /// </summary>
        [DefaultValue("全部分类")]
        [Category("XCI")]
        [Description("全部项文本")]
        public virtual string AllItemCaption { get; set; } = "全部";

        /// <summary>
        /// 数据异步绑定
        /// </summary>
        /// <returns>等待的任务</returns>
        public async Task BindingDataAsync()
        {
            var list = await SysUserService.Instance.SelectListAsync(new SysUserFilter { Status = true, EnableDeptScope = true });
            if (AllItemVisible)
            {
                list.Insert(0, new SysUser
                {
                    Id = string.Empty,
                    Name = AllItemCaption
                });
            }
            DataSource = list;
        }
    }
}